package com.fengling.service.impl;


import com.fengling.mapper.EmpMapper;
import com.fengling.pojo.Emp;
import com.fengling.pojo.PageBean;
import com.fengling.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service

public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageBean page(
            Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        /*PageHelper.startPage(page, pageSize);
        List<Emp> empList = empMapper.showSelect(*//*page,  pageSizename, gender, begin, end*//*);
        Page<Emp> p = (Page<Emp>) empList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;*/
        Integer start = (page - 1) * pageSize;
        List<Emp> empList = empMapper.showSelect(start, pageSize,name,gender,begin,end);
        Long tol =empMapper.count(name, gender, begin, end);
        PageBean pageBean = new PageBean(tol,empList);
        return pageBean;


    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        empMapper.deleteByIds(ids);
    }

    @Override
    public void insert(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);

    }

    @Override
    public Emp selectById(Integer id) {
        return empMapper.selectById(id);
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.login(emp);
    }


}
